package complex.java.serialize;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;

public class HessianSerializable implements ISerializable {
	public void serialize(Order order) throws Exception {
		System.out
				.println("=================HessianSerializable=========================");
		long start = System.currentTimeMillis();
		// 序列化
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		Hessian2Output hessianOutput = new Hessian2Output(output);
		hessianOutput.writeObject(order);
		hessianOutput.flush();// hessian必须flush
		long serialize = System.currentTimeMillis();
		// 反序列化
		ByteArrayInputStream input = new ByteArrayInputStream(
				output.toByteArray());
		Hessian2Input hessianInput = new Hessian2Input(input);
		Order order1 = (Order) hessianInput.readObject();
		long deSerialize = System.currentTimeMillis();
		// System.out.println(order1);
		System.out.println("serialize:" + (serialize - start));
		System.out.println("deSerialize:" + (deSerialize - serialize));
	}
}
